1. /* sdfd2dbl.cpp by K.Tsuru */
  2. // function ID 3001
  3. /********************************************************************
  4. SDouble class
  5. Provides a conversion SDouble --> double.
  6. If you let err = 0, an out of range of double does not terminate the
  7. program and return DBL_MAX or 0.0. The error (OVERFLOW_ERR or UNDERFLOW_ERR)
  8. can be detected by SNError().
  9. Default value is declared as err = 1.
  10. *********************************************************************/
  11. #ifndef SN_H
  12. #include "sn.h"
  13. #endif
  14. static const char* func = "doubleD";
  15. double doubleD(const SDouble& sd, int err){
  16. if(sd.Type() != sd.REAL) SNManager::SetError(sd.RADIX_ERR, func, 3001);
  17. if(sd.SNSign() == 0) return 0.0;
  18. // detect error
  19. long de = sd.DExp();
  20. SNManager::SNErrorFlag error = sd.NO_ERR;
  21. double d = 0.0;
  22. if(de > DBL_MAX_10_EXP-1){
  23. error = sd.OVERFLOW_ERR;
  24. d = DBL_MAX;
  25. }else if( de < DBL_MIN_10_EXP+1 ){
  26. error = sd.UNDERFLOW_ERR;
  27. d = 0.0;
  28. }
  29. if(error != sd.NO_ERR){
  30. if(err) sd.SetError(error, func, 3001);
  31. else sd.SetErrorFlag(error);
  32. return d;
  33. }
  34. RealSize C;
  35. //To get fifteen figures in double it needs
  36. // 0.000x yyyy zzzz aaaa bbbb HHHH(hidden) .... six figures
  37. uint fig = DOUBLE_FIG/DFIGURES +3u;
  38. SDouble x;
  39. x = sd.TakeOutFigures(fig+2u);
  40. x.StdReform(3001);
  41. C.SetEffFig(fig);
  42. x.Round(x.STD_REF | x.CUR_MAX); // round off
  43. C.SetEffFig(0);
  44. uint i = x.First(), last = x.Last();
  45. double qpowFig = dpow10(-DFIGURES), eps = dpow10(-DOUBLE_FIG-DFIGURES);
  46. double r = qpowFig;
  47. d = x[i++]; //d have one figure at least.
  48. for( ; (i <= last) && (r > eps) ; i++){
  49. d += (double)x[i]*r;
  50. r *= qpowFig;
  51. }
  52. //multiply by D^e
  53. int e = x.NetRdxExp()-1;
  54. d *= pow((double)DRADIX, (double)e);
  55. return (x.Sign(3001) > 0) ? d : -d;
  56. }

sdfd2dbl.cpp : last modifiled at 2008/12/15 14:41:56(1,802 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).